home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr53 / pctv4n_1.zip / STATUS.CPP < prev    next >
C/C++ Source or Header  |  1993-06-10  |  3KB  |  101 lines

  1. // status.cpp -- TStatusBar class implementation by Tom Swan
  2.  
  3. #include <owl.h>
  4. #pragma hdrstop
  5. #include "status.h"
  6.  
  7. // Construct status bar object
  8. TStatusBar::TStatusBar(PTWindowsObject AParent)
  9.   : currentID(0), TWindow(AParent, NULL)
  10. {
  11.   Attr.Style = WS_CHILD | WS_VISIBLE | WS_BORDER;
  12.   SetFlags(WB_MDICHILD, FALSE);
  13.   Attr.X = Attr.Y = Attr.W = Attr.H = 0;
  14. }
  15.  
  16. // Perform initializations requiring a window handle
  17. void TStatusBar::SetupWindow()
  18. {
  19.   TEXTMETRIC tm;  // Text "metrics" (i.e. specifications)
  20.   TWindow::SetupWindow();
  21.   // Calculate child height
  22.   HDC hDC = GetDC(HWindow);
  23.   GetTextMetrics(hDC, &tm);
  24.   ReleaseDC(HWindow, hDC);
  25.   childHeight = tm.tmHeight + (tm.tmHeight / 3);
  26.   // Initialize popup menu handles
  27.   HMENU hmenu = GetMenu(Parent->HWindow);
  28.   hmenuSystem = GetSystemMenu(Parent->HWindow, 0);
  29.   hmenuFile = GetSubMenu(hmenu, 0);
  30.   hmenuFont = GetSubMenu(hmenu, 1);
  31.   hmenuWindow = GetSubMenu(hmenu, 2);
  32. }
  33.  
  34. // Modify status bar's registered class 
  35. void TStatusBar::GetWindowClass(WNDCLASS &AWndClass)
  36. {
  37.   TWindow::GetWindowClass(AWndClass);
  38.   AWndClass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  39. }
  40.  
  41. // Adjust size and postion of status bar
  42. void TStatusBar::AdjustSize(WORD parentWidth, WORD parentHeight)
  43. {
  44.   int x = 0, y = parentHeight - childHeight + 1;
  45.   MoveWindow(HWindow, x, y, parentWidth, childHeight, TRUE);
  46. }
  47.  
  48. // Remove status bar's area from client rectangle
  49. void TStatusBar::UMCalcParentClientRect(RTMessage Msg)
  50. {
  51.   ((RECT *)Msg.LParam)->bottom -= childHeight;
  52. }
  53.  
  54. // Show on-line message according to menu selection
  55. void TStatusBar::WMMenuSelect(RTMessage msg)
  56. {
  57.   WORD wIDItem = msg.WParam;       // ID or popup menu handle
  58.   WORD fwMenu = msg.LP.Lo;         // Message flags
  59.   HMENU hmenu = (HMENU)msg.LP.Hi;  // NULL or system menu handle
  60.   int resourceID = 0;
  61.   int menuClosing = ((fwMenu == 0xffff) && (hmenu == 0));
  62.   if (fwMenu & MF_POPUP) {
  63.     if ((HMENU)wIDItem == hmenuSystem) resourceID = 1;
  64.     else if ((HMENU)wIDItem == hmenuFile) resourceID = 2;
  65.     else if ((HMENU)wIDItem == hmenuFont) resourceID = 3;
  66.     else if ((HMENU)wIDItem == hmenuWindow) resourceID = 4;
  67.   } else if (!menuClosing)
  68.     resourceID = wIDItem;
  69.   DisplayString(resourceID);
  70. }
  71.  
  72. // Display string in child window
  73. void TStatusBar::DisplayString(int resourceID)
  74. {
  75.   RECT r;
  76.   char s[128];
  77.  
  78.   s[0] = 0;
  79.   if (resourceID != 0)
  80.     LoadString(GetApplication()->hInstance,
  81.     resourceID, s, sizeof(s));
  82.   currentID = resourceID;  // Save ID for Paint()
  83. // Draw background and "chiseled steel" border
  84.   GetClientRect(HWindow, &r);
  85.   HDC hDC = GetDC(HWindow);
  86.   OffsetRect(&r, 1, 1);
  87.   FillRect(hDC, &r, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
  88.   FrameRect(hDC, &r, (HBRUSH)GetStockObject(DKGRAY_BRUSH));
  89.   OffsetRect(&r, -1, -1);
  90.   FrameRect(hDC, &r, (HBRUSH)GetStockObject(WHITE_BRUSH));
  91. // Draw text in child status-bar window
  92.   SetBkMode(hDC, TRANSPARENT);
  93.   ExtTextOut(hDC, 4, 0, ETO_CLIPPED, &r, s, lstrlen(s), NULL);
  94.   ReleaseDC(HWindow, hDC);
  95. }
  96.  
  97. void TStatusBar::Paint(HDC, PAINTSTRUCT &)
  98. {
  99.   DisplayString(currentID);
  100. }
  101.